package com.yellowpage.wf.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.wf.data.NodeContext;
import com.yellowpage.wf.dao.NodeContextDao;

public class NodeContextServiceImpl extends BaseServiceImpl implements
		NodeContextService {
	private NodeContextDao nodeContextDao;

	public void setNodeContextDao(NodeContextDao nodeContextDao) {
		this.nodeContextDao = nodeContextDao;
	}

	/* White generate Method */
	public NodeContext getNodeContext(Long id) {
		return nodeContextDao.get(id);
	}

	public List<NodeContext> getAllNodeContext() {
		return nodeContextDao.getAll();
	}

	public List<Map> queryNodeContextByPage(Map queryMap, PageRender pageRender) {

		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.NODE_CONTEXT_ID , a.PARAM_NAME , a.WORKFLOW_NODE_ID , a.PARAM_TYPE , a.DEFAULT_VALUE    FROM WF_NODE_CONTEXT a WHERE 1=1 ")
				.addCondition(" and NODE_CONTEXT_ID = :nodeContextId ")
				.addCondition(" and PARAM_NAME = :paramName ").addCondition(
						" and WORKFLOW_NODE_ID = :workflowNodeId ")
				.addCondition(" and PARAM_TYPE = :paramType ").addCondition(
						" and DEFAULT_VALUE = :defaultValue ");

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}

	public List<Map> getNodeContextByNode(Long workflowNodeId) {
		Map queryMap = new HashMap();
		queryMap.put("workflowNodeId", workflowNodeId.toString());
		QueryAssistantSQL sqlAssistant = baseDao
				.newQueryAssistantSQL(
						"SELECT a.NODE_CONTEXT_ID , a.PARAM_NAME , a.WORKFLOW_NODE_ID , a.PARAM_TYPE , a.DEFAULT_VALUE    FROM WF_NODE_CONTEXT a WHERE 1=1 ")
				.addCondition(" and WORKFLOW_NODE_ID = :workflowNodeId ");

		List<Map> resultList = sqlAssistant.query(baseDao.getConnection(),
				queryMap);

		return resultList;
	}

	public void saveNodeContext(NodeContext nodeContext) {
		nodeContextDao.save(nodeContext);
	}

	public void updateNodeContext(NodeContext nodeContext) {
		nodeContextDao.update(nodeContext);
	}

	public void delete(List deleteList) {
		nodeContextDao.remove(deleteList);
	}

}